package com.kwq.user.config;


import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MyMateObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        // strictInsertFill 和 strictUpdateFill 会根据注解中的TableFill策略，字段名和字段类型来判断是否进行填充
        this.strictInsertFill(metaObject,"CREATE_TIME",LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject,"UPDATE_TIME",LocalDateTime.class, LocalDateTime.now());
        // strictStrategy方法 只要填充策略不为DEFAULT，且字段名能对上就会填充
        //this.fillStrategy(metaObject,"createDate",LocalDateTime.now());
        //this.fillStrategy(metaObject,"updateDate",LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject,"UPDATE_TIME",LocalDateTime.class, LocalDateTime.now());
    }
}

